from mininet.topo import Topo
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.cli import CLI
from mininet.node import RemoteController

class MyTopo(Topo):
    def __init__(self):
        Topo.__init__(self)
        s1 = self.addSwitch('s1')
        s2 = self.addSwitch('s2')
        s3 = self.addSwitch('s3')
        h1 = self.addHost('h1', ip='10.0.0.1')
        h2 = self.addHost('h2', ip='10.0.0.2')
        pxy = self.addHost('pxy', ip='10.0.0.3')
        self.addLink(h1, s1)
        self.addLink(h2, s2)
        self.addLink(pxy, s3)
        self.addLink(s1, s3)
        self.addLink(s2, s3)

topo = MyTopo()
net = Mininet(topo=topo, controller=RemoteController)
# net.addNAT().configDefault()
net.start()
net.get('h1').cmd('SERVICE_NAME=h1 python server.py &')
net.get('h2').cmd('SERVICE_NAME=h2 python server.py &')
net.get('pxy').cmd('envoy -c envoy.yaml &')
CLI(net)
net.stop()
